/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package test.entity;

import java.io.File;
import java.sql.Connection;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import javax.swing.JOptionPane;
import model.util.conn.DataBaseConnection;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.view.JasperViewer;

/**
 *
 * @author Pinds
 */
public class testKeuangan {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            String awal = "2011-11-1";
            String akhir = "2011-11-29";
            Properties systemProp = System.getProperties();
            String currentDir = systemProp.getProperty("user.dir");
            File dir = new File(currentDir);
            String reportName = "laporanKeuangan.jrxml";
            String gambar = "flower1.png";
            String reportDirName = "Report" + File.separatorChar + "Keuangan";
            File fileRpt;
            File fileGambar;
            String fullPathReport = "";
            String fullPathGambar = "";
            if (dir.isDirectory()) {
                String[] isiDir = dir.list();
                for (int i = 0; i < isiDir.length; i++) {
                    fileRpt = new File(currentDir + File.separatorChar + reportDirName + File.separatorChar + reportName);
                    fileGambar = new File(currentDir + File.separatorChar + reportDirName + File.separatorChar + gambar);
                    if (fileRpt.isFile()) {
                        fullPathReport = fileRpt.toString();
                    }
                    if (fileGambar.isFile()) {
                        fullPathGambar = fileGambar.toString();
                    }
                }
            }
            Connection conn = DataBaseConnection.getConnection();
            JasperReport jasperReport = JasperCompileManager.compileReport(fullPathReport);
            Map params = new HashMap();
            params.put("PRM_KD_TGL_AWAL", java.sql.Date.valueOf(awal));
            params.put("PRM_KD_TGL_AKHIR", java.sql.Date.valueOf(akhir));
            params.put("PRM_KD_GAMBAR", fullPathGambar);
            JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, conn);
            JasperViewer.viewReport(jasperPrint, false);
        } catch (JRException ex) {
            JOptionPane.showMessageDialog(null, ex, "Error", JOptionPane.ERROR_MESSAGE);
        } catch (NoSuchMethodError ns) {
            JOptionPane.showMessageDialog(null, ns, "Error", JOptionPane.ERROR_MESSAGE);
        } catch (NullPointerException ns) {
            JOptionPane.showMessageDialog(null, ns, "Error", JOptionPane.ERROR_MESSAGE);
        }
    }
}
